package com.itheima.d7_interface_demo;

import java.util.ArrayList;

public class StudentOperatorImpl1 implements StudentOperator{
    @Override
    public void printAllInfo(ArrayList<Student> stus) {
//        打印班级全部学生信息，包含男女人数
        int count1 = 0;//男
        int count2 = 0;//女
        System.out.println("----------------------------");
        for (int i = 0; i < stus.size(); i++) {
            Student student = stus.get(i);
            //打印全部信息
            System.out.println(student.toString());
            if(student.getSex()=='男'){
                count1++;
            }else{
                count2++;
            }
        }
        System.out.println("男生人数"+count1   +"女生人数"+count2);
        System.out.println("------------------");

    }

    @Override
    public void printAvgScore(ArrayList<Student> stus) {
        //d打印全班平均成绩,去掉最高分和最低分
        double MaxScore = stus.get(0).getScore();//最高分
        double MinScore = stus.get(0).getScore();//最低分
        double AllScore = 0.0;
        for (int i = 0; i < stus.size(); i++) {
            Student student = stus.get(i);
            //获取所有成绩
           AllScore += student.getScore();
           //获取最大值
           if(MaxScore<student.getScore()){
               MaxScore=student.getScore();
           }
           //获取最小值
           if(MinScore>student.getScore()){
               MinScore=student.getScore();
           }
        }
        System.out.println("学生平均成绩是"+AllScore/stus.size());
        System.out.println("去掉最高分和最低分的平均成绩是");
        System.out.println((AllScore-MaxScore-MinScore)/(stus.size()-2));

    }
}
